package collection.homework.Collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Objects;

/**
 * contains()
 * remove()
 */
public class CollectionDemo2 {
    public static void main(String[] args) {
        Collection a = new ArrayList();
        a.add(new Point(1,2));
        a.add(new Point(3,4));
        a.add(new Point(5,6));
        a.add(new Point(7,8));
        System.out.println("a集合："+a);//a集合：[(x=1,y=2), (x=3,y=4), (x=5,y=6), (x=7,y=8)]

        Point b = new Point(1,2);
        boolean bool = a.contains(b);
        System.out.println("是否包含："+bool);//true

        boolean bool2 = a.remove(b);
        System.out.println("是否删除："+bool2);//true
        System.out.println("删除后的a的集合："+a);//删除后的a的集合：[(x=3,y=4), (x=5,y=6), (x=7,y=8)]
    }
}



class Point{
    private int x;
    private int y;

    public Point() {
    }
    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public String toString() {
        return "(x="+x+",y="+y+")";
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Point point = (Point) o;
        return x == point.x && y == point.y;
    }

    @Override
    public int hashCode() {
        return Objects.hash(x, y);
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }
}